package com.rain.shoppingscienceproj.ui.activity.setting;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.rain.shoppingscienceproj.R;
import com.rain.shoppingscienceproj.ui.activity.BaseActivity;
import com.rain.shoppingscienceproj.ui.base.GlobalData;
import com.rain.shoppingscienceproj.ui.utile.DialogUtils;
import com.rain.shoppingscienceproj.ui.utile.TitleUtils;
import com.rain.shoppingscienceproj.utils.AppManager;
import com.rain.shoppingscienceproj.utils.ImageUtils;
import com.rain.shoppingscienceproj.utils.SharedPreferencesUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 设置
 */
public class SettingActivity extends BaseActivity {

    @OnClick(R.id.user_info)
    void userInfo() {
        startActivitys(UserInfoActivity.class);
    }

    @BindView(R.id.head_img)
    ImageView head_img;

    @BindView(R.id.user_name)
    TextView user_name;

    @BindView(R.id.tv_member)
    TextView tv_member;


    @OnClick(R.id.license)
    void license() {
        startActivitys(FeedbackActivity.class);
    }

    @OnClick(R.id.rl_about)
    void about() {
        startActivitys(AbountActivity.class);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        AppManager.getAppManager().addActivity(this);
        ButterKnife.bind(this);
        TitleUtils.TitleView(this, "设置");
        initData();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        initData();
    }

    private void initData() {
        userInfo = GlobalData.getUserInfo();
        user_name.setText(userInfo.getNickname());
        tv_member.setText(userInfo.getUsername());
        if (null != userInfo.getAvatarurl() || !"".equals(userInfo.getAvatarurl())) {
            ImageUtils.imageCircle(this, userInfo.getAvatarurl(), head_img);
        }
    }

    @OnClick(R.id.logout)
    void exic() {
        DialogUtils.dialog(this, "您确定要退出当前账号吗?");
        DialogUtils.getTv_sure().setOnClickListener(v -> exit());
    }

    private void exit() {
        SharedPreferencesUtil.putString(SettingActivity.this, "AppShopping", "AppShopping", "");
        GlobalData.setUserInfo(null);
        AppManager.getAppManager().AppExit(SettingActivity.this);
        DialogUtils.dismissDialog();
        finish();
    }
}
